abstract class CashSuper {
  public abstract AcceptCash(money: number): number;
}
class CashNormal extends CashSuper {
  AcceptCash(money: number): number {
    return money;
  }
}

class CashRebate extends CashSuper {
  private moneyRebate = 0.0;
  constructor(moneyRebate: number) {
    super();
    this.moneyRebate = moneyRebate;
  }

  AcceptCash(money: number): number {
    return money * this.moneyRebate;
  }
}

class CashReturn extends CashSuper {
  private moneyCondition = 0.0;
  private moneyReturn = 0.0;

  constructor(moneyCondition: number, moneyReturn: number) {
    super();
    this.moneyCondition = moneyCondition;
    this.moneyReturn = moneyReturn;
  }

  AcceptCash(money: number): number {
    let result = money;
    if (money >= this.moneyCondition) {
      result =
        money - Math.floor(money / this.moneyCondition) * this.moneyReturn;
    }

    return result;
  }
}

export class CashFactory {
  public static CreateCashAccept(type: string): CashSuper | null {
    let cs: CashSuper | null = null;

    switch (type) {
      case "正常收费":
        cs = new CashNormal();
        break;
      case "满300返100":
        cs = new CashReturn(300, 100);
        break;
      case "打八折":
        cs = new CashRebate(0.8);
        break;
    }
    return cs;
  }
}
